package cz.muni.fi.pv112.cranesimulator.utils.handlers.inputs;

import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 *
 * @author Michal Ďuriš
 */
public class KeyInputHandler {

    private final Map<Integer, Boolean> keymap = new HashMap<>();

    private KeyInputHandler() {
    }

    public static KeyInputHandler getInstance() {
        return KeyInputHandlerHolder.INSTANCE;
    }

    private static class KeyInputHandlerHolder {

        private static final KeyInputHandler INSTANCE = new KeyInputHandler();
    }

    public void processKeyInput(KeyEvent keyEvent, boolean keyPressed) {
        keymap.put(keyEvent.getExtendedKeyCode(), keyPressed);
    }

    public Iterator<Entry<Integer, Boolean>> getKeymapView() {
        return keymap.entrySet().iterator();
    }

    public boolean isKeyPressed(int key) {
        return keymap.get(key) == null ? false : keymap.get(key);
    }

}
